import React, { Component } from 'react'
import Header from '../../Common/Header'
import { Link } from 'react-router-dom'
import { connect } from 'react-redux'
import { dzaddress_action } from '../../../store/store';
class Shdz extends Component {
    constructor() {
        super();
        this.state = {
            oIndex: 0
        }
    }
    render() {
        return (
            <div className="shdz">
                <Header title="我的收货地址" back={<span onClick={() => { this.props.history.push({ pathname: '/my' }) }}>&lt;</span>}></Header>
                <div className="content">
                    <div className="list">
                        {
                            this.props.adddz.length > 0
                                ?
                                this.props.adddz.map((item, index) => {
                                    return (
                                        <div className={this.props.dzaddress.id === item.id ? "item aacc" : 'item'} key={index} onClick={() => { this.setState({ oIndex: index }); this.props.setdz(item) }}>
                                            <div className="left" >
                                                <div className="dz">地址：{item.dz}  门牌号：{item.mph}</div>
                                                <div className="user">联系人：{item.lxr} 电话：{item.dh}</div>
                                            </div>
                                            <div className="bj" onClick={() => { this.props.history.push({ pathname: '/xgdz', state: item }) }}>编辑</div>
                                            <div className="mrdz">默认地址</div>
                                        </div>
                                    )
                                })
                                :
                                <div className="mydz">还没有添加地址</div>
                        }
                    </div>
                    <Link to="/xzdz" className="adddz">新增地址</Link>
                </div>
            </div>
        )
    }
}
export default connect(
    (state) => {
        return {
            adddz: state.adddz,
            dzaddress: state.dzaddress
        }
    },
    (dispatch) => {
        return {
            setdz: (item) => {
                dispatch(dzaddress_action(item))
            }
        }
    }
)(Shdz)